package evil.wolf.business;

import evil.wolf.db.DatabaseManager;
import evil.wolf.excute.query.ExcuteQuery;
import evil.wolf.objects.ObjectCTNhapXuat;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;


public class BusinessCTNhapXuat {
	
	DatabaseManager databaseManager;	
	ExcuteQuery exc;
	public int colCount;
	public String colName[];

	public BusinessCTNhapXuat() {
		
		databaseManager = new DatabaseManager();
		exc = new ExcuteQuery();
		
	}
	
	public int getColumn(){
		return colCount;
	}
	
	public String[] getName(){
		return colName;
	}
	
	public List<ObjectCTNhapXuat> getListRecords() {
		
		List<ObjectCTNhapXuat> rowList = new ArrayList<>();
		
		try {
			ResultSet rsCT = databaseManager.getResultSet(exc.selectCTNhapXuat());
			ResultSetMetaData meta = rsCT.getMetaData();
			colCount = meta.getColumnCount();
			colName = new String[colCount];
			
			for (int h = 0; h < colCount; h++) {
				colName[h] = meta.getColumnName(h + 1);
			}
			
			while (rsCT.next()) {
				
				ObjectCTNhapXuat newobjectCTNhapXuat = new ObjectCTNhapXuat();
				
				newobjectCTNhapXuat.setsoct(rsCT.getString(1));
				newobjectCTNhapXuat.setmak(rsCT.getString(2));
				newobjectCTNhapXuat.setmah(rsCT.getString(3));
				newobjectCTNhapXuat.setsl(rsCT.getInt(4));
				newobjectCTNhapXuat.setdg(rsCT.getInt(5));
				newobjectCTNhapXuat.settg(rsCT.getInt(6));
				
				rowList.add(newobjectCTNhapXuat);
			}
			databaseManager.closeConnect();
		} catch (SQLException e) {

			JOptionPane.showMessageDialog(null, e.toString(), "ERROR", JOptionPane.INFORMATION_MESSAGE);
			e.printStackTrace();
		}
		return rowList;
	}
}
